package com.gas.gm.service;

import java.util.List;

import org.springframework.stereotype.Service;

import com.gas.gm.dao.MessageDao;
import com.gas.gm.model.Message;
import com.gas.gm.util.GasContextHelper;

@Service("messageService")
public class IMessageService implements MessageService {
	
	private MessageDao messageDao;

	public void createMessage(Message m) {
		getMessageDao().persist(m);
	}

	public void removeMessage(Message m) {
		getMessageDao().remove(m);
	}

	public Message updateMessage(Message m) {
		return getMessageDao().merge(m);
	}

	public Message findMessage(Long id) {
		return getMessageDao().findMessage(id);
	}

	public List<Message> findAllMessages() {
		return getMessageDao().findAllMessages();
	}
	
	MessageDao getMessageDao(){
		if(messageDao==null){
			messageDao=GasContextHelper.getApplicationContext().getBean(MessageDao.class);
		}
		return messageDao;
	}

}
